package com.chinacache.pqbs.dao.user;

import org.springside.modules.orm.jpa.GenericDAO;

import com.chinacache.pqbs.entity.user.User;

/**
 * User的DAO类.
 * 
 * 继承于泛型DAO基类GenericDAO,默认拥有增删改查的基本函数.
 * 用泛型定义管理的Entity类型为User,User的主键类型为Integer.
 * 
 * @see GenericDAO
 * @author calvin
 */
public class UserDAO extends GenericDAO<User, Integer> {

	//使用静态变量定义JPQL语句.
	private static final String COUNT_USER_BY_AUTH = "SELECT COUNT(user) FROM User user where user.loginName=? and password=?";

	public User findByLoginName(Object loginName) {
		return findUniqueByProperty("loginName", loginName);
	} 
	/**
	 * 统计符合认证信息参数的帐号的数量.
	 */
	@SuppressWarnings("unchecked")
	public long countByAuthInfo(String loginName, String password) {
		return (Long) findUnique(COUNT_USER_BY_AUTH, loginName, password);
	} 
 
}